package com.ruoyi.dynamic.controller.app;

import com.ruoyi.common.core.constant.constant.PathConstant;
import com.ruoyi.common.core.context.SecurityContextHolder;
import com.ruoyi.common.core.pojo.vo.BaseVO;
import com.ruoyi.common.core.pojo.vo.MultiVO;
import com.ruoyi.common.core.result.Result;
import com.ruoyi.dynamic.model.pojo.entity.RoomInteract;
import com.ruoyi.dynamic.model.pojo.entity.RoomNotice;
import com.ruoyi.dynamic.model.pojo.request.app.AppRoomChumApplyRequest;
import com.ruoyi.dynamic.model.pojo.request.app.AppRoomInteractAddRequest;
import com.ruoyi.dynamic.model.pojo.request.app.AppRoomUserSearchRequest;
import com.ruoyi.dynamic.model.pojo.request.app.AppRoomWishCloseRequest;
import com.ruoyi.dynamic.service.IRoomInteractService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Tag(name = "App-房间互动挑战相关", description = "App-房间互动挑战相关")
@RestController
@RequestMapping(PathConstant.APP_PATH + "room-interact")
public class AppRoomInteractController {

    private final IRoomInteractService iRoomInteractService;

    public AppRoomInteractController(IRoomInteractService iRoomInteractService) {
        this.iRoomInteractService = iRoomInteractService;
    }

    @Operation(summary = "添加", description = "添加")
    @PostMapping("add")
    public BaseVO add(@RequestBody @Valid AppRoomInteractAddRequest request) {
        Long userId = SecurityContextHolder.getUserId();
        boolean add = iRoomInteractService.add(request, userId);
        return Result.success();
    }

    @Operation(summary = "删除", description = "删除")
    @GetMapping("remove")
    public BaseVO remove(Long id) {
        return Result.successOrFail(iRoomInteractService.removeById(id));
    }

    @Operation(summary = "列表", description = "列表")
    @GetMapping("list")
    public MultiVO<RoomInteract> list(@Valid AppRoomUserSearchRequest request) {
        return Result.multi(iRoomInteractService.listByRoomId(request, SecurityContextHolder.getUserId()));
    }

    @Operation(summary = "发起互动", description = "发起互动")
    @PostMapping("launch")
    public BaseVO launch(@RequestBody @Valid AppRoomWishCloseRequest request) {
        Long userId = SecurityContextHolder.getUserId();
        boolean add = iRoomInteractService.launch(request, userId);
        return Result.success();
    }

    @Operation(summary = "结束互动", description = "结束互动")
    @PostMapping("over")
    public BaseVO over(@RequestBody @Valid AppRoomWishCloseRequest request) {
        Long userId = SecurityContextHolder.getUserId();
        boolean add = iRoomInteractService.over(request, userId);
        return Result.success();
    }


}
